package ac.github.os.internal.core.script.impl

import ac.github.os.internal.core.script.BaseWrapper
import ac.github.os.internal.core.script.InternalConfig
import ac.github.os.internal.core.script.InternalScript
import ac.github.os.internal.core.trigger.PlayerTrigger
import ac.github.os.internal.core.trigger.Trigger
import org.bukkit.attribute.Attribute
import org.bukkit.entity.Player
import taboolib.common.platform.Awake

@Awake
class PlayerScript : InternalScript<PlayerScript.Wrapper> {

    override val name: String
        get() = "player"

    override fun execute(trigger: Trigger?, wrapper: Wrapper, config: InternalConfig, string: String): String? {
        return if (trigger is PlayerTrigger) {
            val player = trigger.player
            when (string) {
                "name" -> player.name
                "level" -> player.level.toString()
                "health" -> player.health.toString()
                "max-health" -> player.getAttribute(Attribute.GENERIC_MAX_HEALTH)!!.baseValue.toString()
                "pitch" -> player.location.pitch.toString()
                "pitch:r" -> (-player.location.pitch).toString()
                "yaw" -> player.location.yaw.toString()
                "yaw:r" -> (-player.location.yaw).toString()
                "hand:slot" -> player.inventory.heldItemSlot.toString()
                else -> null
            }
        } else "trigger type not enough."
    }

    class Wrapper : BaseWrapper

}